package com.wechat.admin.model.enums;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

/**
 * @Author:sjb
 * @CreateTime:2024-12-14
 * @Description: 用户角色相关枚举类
 * @Version：1.0
 */
@Getter
public enum UserRoleEnum {


    USER("user","普通用户"),
    ADMIN("admin","管理员"),
    SUPER_ADMIN("superAdmin","超级管理员");

    private final String value;

    private final String text;

    UserRoleEnum(String value, String text) {
        this.value = value;
        this.text = text;
    }

    /**
     * 根据value获取对应的枚举值
     * @param value
     * @return
     */
    public static UserRoleEnum getEnumByValue(String value){
        if (ObjectUtil.isEmpty(value)){
            return null;
        }

        for (UserRoleEnum userRoleEnum : UserRoleEnum.values()) {
            if (userRoleEnum.getValue().equals(value)){
                return userRoleEnum;
            }
        }
        return null;
    }

    /**
     * 根据value获取对应的枚举值
     * @param text
     * @return
     */
    public static UserRoleEnum getEnumByText(String text){
        if (ObjectUtil.isEmpty(text)){
            return null;
        }

        for (UserRoleEnum userRoleEnum : UserRoleEnum.values()) {
            if (userRoleEnum.getText().equals(text)){
                return userRoleEnum;
            }
        }
        return null;
    }
}
